<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport"
			content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../../css/common.css" media="all">

	</head>

	<body>

		<div class="layui-fluid">
			<div class="layui-row" id="view">
				<form class="layui-form" lay-filter="test_detail">
					<div class="layui-card">
						<div class="layui-card-body">
							<div class="layui-form-item">
								<label class="layui-form-label"><text class='text_red_color'>*</text>开店合伙人：</label>
								<div class="layui-input-inline">
									<input type="text" name="agentname" lay-verify="required" placeholder="选择合伙人"
										autocomplete="off" class="layui-input agentname">
									<input type="hidden" name="agentid" lay-verify="required" autocomplete="off"
										class="layui-input agentid">
								</div>
								<div class="layui-form-mid layui-word-aux">
									<a href="Javascript:;" onclick="searchdata()">选择</a>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">城市代理：</label>
								<div class="layui-input-inline">
									<input type="text" name="city_shopname" placeholder="选择城市代理" autocomplete="off"
										class="layui-input city_shopname">
									<input type="hidden" name="city_shopid" autocomplete="off"
										class="layui-input city_shopid">
								</div>
								<div class="layui-form-mid layui-word-aux">
									<a href="Javascript:;" onclick="areadata()">选择</a>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">区域代理：</label>
								<div class="layui-input-inline">
									<input type="text" name="area_shopname" placeholder="选择区域代理" autocomplete="off"
										class="layui-input area_shopname">
									<input type="hidden" name="area_shopid" autocomplete="off"
										class="layui-input area_shopid">
								</div>
								<div class="layui-form-mid layui-word-aux">
									<a href="Javascript:;" onclick="areadata()">选择</a>
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">用户编号</label>
									<div class="layui-input-inline">
										<input type="text" name="userid" placeholder="请输入用户编号" autocomplete="off"
											class="layui-input">
									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">会员编号</label>
									<div class="layui-input-inline">
										<input type="text" name="member" placeholder="请输入会员编号" autocomplete="off"
											class="layui-input">
									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">店铺名称</label>
									<div class="layui-input-inline">
										<input type="text" name="name" placeholder="请输入店铺名称" autocomplete="off"
											class="layui-input">
									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">师傅佣金</label>
									<div class="layui-input-inline">
										<input type="text" name="master_fee" placeholder="请输入师傅佣金" autocomplete="off"
											class="layui-input">
									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">店铺介绍</label>
									<div class="layui-input-inline">
										<input type="text" name="notes" placeholder="请输入店铺介绍" autocomplete="off"
											class="layui-input">
									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">店铺头像</label>
								<div class="layui-input-block">
									<button type="button" class="layui-btn layui-btn-normal"
										onclick="choose(0)">上传图片</button>
									<ul class="show_img_ul" id="head_img"></ul>
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">联系电话</label>
									<div class="layui-input-inline">
										<input type="text" name="mobile" placeholder="请输入联系电话" autocomplete="off"
											class="layui-input">
									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">详细地址</label>
								<div class="layui-input-block" style="display: flex;">
									<textarea class="layui-textarea" id="address1" name="address"
										placeholder="请输入详细地址"></textarea>
									<button id="dian" style="margin-left: 10px;" type="button"
										class="layui-btn layui-btn-normal">搜索位置</button>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">经度</label>
								<div class="layui-input-inline">
									<input type="text" id="lng" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">纬度</label>
								<div class="layui-input-inline">
									<input type="text" id="lat" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<div id="maplocation" style="width:500px;height:500px;"></div>
							</div>
						</div>
					</div>
					<div class="layui-form-item layui-layout-admin">
						<div class="layui-input-block">
							<div class="layui-footer" style="left: 0;">
								<button class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>
		<script src="../../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../../js/jquery.min.js"></script>
		<script src="https://api.lishuahuoban.cn/layuiadmin/city.data.js"></script>
		<script src="../../../../js/common.js"></script>
		<script>
			var _data = {
				id: getParam('id')
			}
			layui.config({
				base: '../../../../layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index', //主入口模块
				location: 'location/location',
			}).use(['index', 'form', 'laytpl', 'laydate'], function() {
				var $ = layui.$,
					admin = layui.admin,
					laytpl = layui.laytpl,
					laydate = layui.laydate,
					form = layui.form;

				var area_cn_arr = [],
					img_arr2 = [];
				img_arr0 = [];


				agent_type_show('radio')
				on_off_show('radio')
				//				initroledatashow('option')
				//				initsite_unionshow('option')
				if (_data.id) {
					initdata();
				}
				//监听提交
				form.on('submit(demo1)', function(data) {
					var data = data.field;
					_data = Object.assign(_data, data);
					_data.card_status = 0;
					_data.head_img = img_arr0.join(',');
					//_data.area_cn = area_cn_arr.join(',')

					layer.confirm('确定要提交数据？', function() {
						loading();
						if (_data.id) {
							submitdata(_data, server.agent_member_shop_edit);
						} else {
							delete _data.id;
							submitdata(_data, server.agent_member_shop_insert);
						}
					}, function() {
						layer.msg('取消操作');
					});
					return false;
				});
				window.searchdata = function(type) {
					layer.open({
						type: 2,
						title: '选择',
						shadeClose: false,
						shade: 0.5,
						maxmin: true, //开启最大化最小化按钮
						area: ['90%', '90%'],
						content: 'list.html',
						end: function() {},
						success: function() {}
					});
				}
				window.areadata = function(type) {
					layer.open({
						type: 2,
						title: '选择',
						shadeClose: false,
						shade: 0.5,
						maxmin: true, //开启最大化最小化按钮
						area: ['90%', '90%'],
						content: 'area_select.html',
						end: function() {},
						success: function() {}
					});
				}


				var position = ''

				function getpositions(_data) {
					$.ajax({
						type: "get",
						url: "https://restapi.amap.com/v3/geocode/geo?output=JSON&address=" + _data +
							"&key=280802ed0116fef931dbcf5e7e9278d7&radius=1000&extensions=all",
						async: false,
						success: function(res) {
							position = res.geocodes[0].location
							console.log("搜索位置：" + position)

							var lng = res.geocodes[0].location.split(',')[0]
							var lat = res.geocodes[0].location.split(',')[1]


							var map = new BMap.Map("maplocation"); // 创建Map实例
							var point = new BMap.Point(lng, lat); // 创建点坐标
							map.centerAndZoom(point, 15);
							map.enableScrollWheelZoom(); //启用滚轮放大缩小


							var myCity = new BMap.LocalCity();
							var marker = new BMap.Marker(map.getCenter())
							map.addOverlay(marker);
							marker.enableDragging();
							map.addEventListener("click", function(e) {
								position = e.point.lng + ", " + e.point.lat
								console.log("点击位置：" + position)
								$('#lng').val(e.point.lng);
								$('#lat').val(e.point.lat);
								map.panTo(new BMap.Point(e.point.lng, e.point
									.lat)); // map.panTo方法，把点击的点设置为地图中心点  
							});
							marker.addEventListener("dragend", function(e) {
								$("#lng").val(e.point.lng);
								$("#lat").val(e.point.lat);
								console.log("当前位置：" + e.point.lng + ", " + e.point.lat)
							})
							map.addEventListener("tilesloaded", function() {
								var newpoint = map.getCenter();
								marker.setPosition(newpoint);
							});
						}
					});
				}

				function submitdata(_data, _url) {
					$.post(_url, _data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								layer.alert('操作成功', function() {
									parent.layer.closeAll();
									parent.layui.table.reload('test-table-operate');
								});
								layer.closeAll('loading');
							} else {
								layer.msg(res.msg);
								layer.closeAll('loading');
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				}

				window.choose = function(data) {
					layer.open({
						type: 2,
						title: '上传图片',
						shadeClose: false,
						shade: 0.5,
						maxmin: true, //开启最大化最小化按钮
						area: ['700px', '400px'],
						content: '../../../model/up_report_one.html?type=' + data,
						end: function() {},
						success: function() {}
					});
				}

				window.getimg = function(data, type) {
					console.log(data);
					if (data) {
						switch (type) {
							case '0':
								createli(data, 'head_img', type)
								break;
							default:
								break;
						}
					}
				}
				window.delimg = function(i, type, _self) {
					var _type = String(type)
					layer.confirm('确定要删除图片？', function(index) {
						switch (_type) {
							case '0':
								img_arr0.splice(i, 1)
								break;
							default:
								break;
						}
						$(_self).parent().remove();
						layer.close(index)
					}, function() {
						layer.msg('取消操作');
					});
				}

				function createli(data, dom, type) {
					var lihtml = '';
					switch (type) {
						case '0':
							if (data.indexOf(',') == -1) {
								img_arr0.splice(0, 1, data)
							} else {
								for (var i = 0; i < data.split(',').length; i++) {
									img_arr0.push(data.split(',')[i])
								}
							}
							for (var i = 0; i < img_arr0.length; i++) {
								lihtml += '<li class="show_img_li1">' +
									'<img src=' + img_arr0[i] + ' >' +
									'<p onclick="delimg(' + i + ',0,this)">删除</p>' +
									'</li>'
							}
							break;
						default:
							break;
					}
					$('#' + dom).html(lihtml);
				}

				function initdata() {
					$.get(server.agent_member_shop_detail, _data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								var data = res.agent_member_shop
								data.data.head_img ? createli(data.data.head_img, 'head_img', '0') : '',
									//								data.data.front ? createli(data.data.front, 'front', '1') : ''
									//								data.data.back ? createli(data.data.back, 'back', '2') : ''

									//								if($("select[name=area_cn] option").length > 0) {
									//									$("select[name=area_cn]").val(data.data.area_id);
									//								}
									//								if(data.data.area_id) {
									//									queryareadata1(data.data.area_id, 'area_id')
									//								}

									form.val("test_detail", data.data);
								form.render();
							} else {
								layer.msg(res.msg);
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				}

				var htmlSelect = function(optionData, selectname) {
					var html = '';
					html += '<div class="layui-input-inline">';
					html += ' <select lay-filter=' + selectname + ' name=' + selectname + '>';
					html += '  <option value="">请选择</option>';
					for (var i = 0; i < optionData.length; i++) {
						html += ' <option value=' + optionData[i].id + ' title=' + optionData[i].id + '>' +
							optionData[i].name +
							'</option>';
					}
					html += ' </select>';
					html += '</div>';
					return html;
				}

				function loadJScript() {
					var script = document.createElement("script");
					script.type = "text/javascript";
					script.src = "//api.map.baidu.com/api?v=2.0&ak=你的key&callback=init";
					document.body.appendChild(script);
				}


				window.init = function() {
					var map = new BMap.Map("maplocation"); // 创建Map实例
					var point = new BMap.Point(113.698531, 34.756137); // 创建点坐标
					map.centerAndZoom(point, 15);
					map.enableScrollWheelZoom(); //启用滚轮放大缩小

					function myFun(result) {
						var cityName = result.name;
						map.setCenter(cityName);
					}
					var myCity = new BMap.LocalCity();
					myCity.get(myFun);
					var marker = new BMap.Marker(map.getCenter()); // 创建标注
					map.addOverlay(marker); // 将标注添加到地图中
					marker.enableDragging(); //可拖拽
					//marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
					map.addEventListener("click", function(e) {
						// alert(e.point.lng+","+e.point.lat);// 单击地图获取坐标点；
						console.log("当前位置：" + e.point.lng + ", " + e.point.lat)
						$('#lng').val(e.point.lng);
						$('#lat').val(e.point.lat);
						map.panTo(new BMap.Point(e.point.lng, e.point.lat)); // map.panTo方法，把点击的点设置为地图中心点  
					});
					marker.addEventListener("dragend", function(e) { //拖拽标注获取标注坐标
						//alert("当前位置：" + e.point.lng + ", " + e.point.lat);           //可拖拽的标注 
						$("#lng").val(e.point.lng);
						$("#lat").val(e.point.lat);
						console.log("当前位置：" + e.point.lng + ", " + e.point.lat)
					})
					//加载完成之后,改变标注点坐标,使之和当前定位的城市基本相符
					map.addEventListener("tilesloaded", function() {
						var newpoint = map.getCenter();
						marker.setPosition(newpoint);
					});


				}
				loadJScript()
				layui.use('layer', function() {
					var layer = layui.layer;
				})
				$("#dian").click(function() {
					console.log()
					var address = $('#address1').val()
					getpositions(address)
					_data.positions = position
					//  layer.open({
					//      type:1,
					//      area:"500px",
					//      title:"选取位置",
					//      content:$('#maplocation'),
					//      success:function(){
					//         var map = new BMap.Map("maplocation"); // 创建地图实例 
					//         map.enableScrollWheelZoom();   //启用滚轮放大缩小，默认禁用
					//         var point = new BMap.Point(116.404, 39.915); // 创建点坐标 
					//         map.centerAndZoom(point, 12);
					//         function myFun(result){
					//             var cityName = result.name;
					//             map.setCenter(cityName);
					//         }
					//         var myCity = new BMap.LocalCity();
					//         myCity.get(myFun);
					//         var marker = new BMap.Marker(map.getCenter());  // 创建标注
					//         map.addOverlay(marker);               // 将标注添加到地图中
					//         marker.enableDragging();                //可拖拽
					//         //marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
					//         map.addEventListener("click",function(e){  
					//              // alert(e.point.lng+","+e.point.lat);// 单击地图获取坐标点；
					// console.log("当前位置：" + e.point.lng + ", " + e.point.lat)
					//              $('#lng').val(e.point.lng);
					//              $('#lat').val(e.point.lat);
					//              map.panTo(new BMap.Point(e.point.lng,e.point.lat));// map.panTo方法，把点击的点设置为地图中心点  
					//         }); 
					//         marker.addEventListener("dragend", function(e){                    //拖拽标注获取标注坐标
					//              //alert("当前位置：" + e.point.lng + ", " + e.point.lat);           //可拖拽的标注 
					//              $("#lng").val(e.point.lng);
					//             $("#lat").val(e.point.lat);
					// console.log("当前位置：" + e.point.lng + ", " + e.point.lat)
					//         })
					//         //加载完成之后,改变标注点坐标,使之和当前定位的城市基本相符
					//         map.addEventListener("tilesloaded",function(){
					//             var newpoint = map.getCenter();
					//             marker.setPosition(newpoint);
					//         });
					//      },
					//      cancel:function(){
					//      }
					//  });
				});

			});
		</script>
	</body>

</html>